﻿using Abp.Application.Services.Dto;
using Abp.Web.Mvc.Authorization;
using Akso.Authorization;
using Akso.CodeGroups;
using Akso.Web.Areas.BasicDataModule.Models.CodeGroups;
using Akso.Web.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Akso.Web.Areas.BasicDataModule.Controllers
{
    [AbpMvcAuthorize(AppPermissions.Pages_BasicDataModule_CodeSettings)]
    public class CodeGroupsController : AbpZeroTemplateControllerBase
    {
        // GET: BasicDataModule/CodeGroups
        private readonly ICodeGroupAppService _codegroupsAppService;
        public CodeGroupsController(ICodeGroupAppService codegroupsAppService)
        {
            _codegroupsAppService = codegroupsAppService;
        }
        public ActionResult Index()
        {
            var model = new CodeGroupsViewModel
            {
                FilterText = Request.QueryString["filterText"]
            };
            return View(model);
        }
        /// <summary>
        /// 为新增、编辑数据页面加载数据，弹出修改页面框。
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AbpMvcAuthorize(AppPermissions.Pages_BasicDataModule_CodeGroups_Create, AppPermissions.Pages_BasicDataModule_CodeGroups_Edit)]
        public async Task<PartialViewResult> CreateOrEditModal(Guid? id)
        {
            var output = await _codegroupsAppService.GetObjectForEdit(new NullableIdDto<Guid> { Id = id });
            var viewModel = new CreateOrEditCodeGroupModalViewModel(output);

            return PartialView("_CreateOrEditModal", viewModel);
        }
    }
}